package com.shujia.network;

import java.net.InetAddress;

public class InetAddressDemo {

    public static void main(String[] args) throws Exception {
//        public static InetAddress getByName(String host)
        // 指定ip获取InetAddress对象
        InetAddress inetAddress = InetAddress.getByName("192.168.20.15");
        // public static InetAddress getLocalHost()
        inetAddress = InetAddress.getLocalHost();
//        inetAddress = InetAddress.getByName("127.0.0.1");
        // public boolean isReachable(int timeout)：测试是否可以达到该地址
        boolean flag = inetAddress.isReachable(100);
        System.out.println(flag);


//        public String getHostAddress()：返回 IP 地址字符串（以文本表现形式）
        String ip = inetAddress.getHostAddress();
        System.out.println(ip);

//        public String getHostName()：获取此 IP 地址的主机名
        String hostName = inetAddress.getHostName();
        System.out.println(hostName);

    }
}
